import { StoreFuncs } from "../../ExcelStore";
import { message } from "antd";
import { getLabel } from "../../../../util/convert";

export interface IChangeValueOptions {
    row: number;
    rowCount: number;
    col:number;
    colCount :number;
    selections:any;
    str :string;
    sheetName: string;
    oldDatas: any;
}
export default {
    canUndo: true,
    execute: (context: GC.Spread.Sheets.Workbook, options: IChangeValueOptions, isUndo: boolean) => {
        const  {selections}  = options;
        const store = StoreFuncs.getInstance();
        const datas: any[] = store.dataSource.getValue('datas') as any[];
        let rowData: any = [];
        for (let index = 0; index < selections.length; index++) {
            const selection = selections[index];
            let {row,rowCount} = selection;
            for (let j = 0; j <rowCount; j++) {
                const randomFieldId  =datas[row+j].randomFieldId  as string;
                if(randomFieldId.indexOf("-")<0){
                    continue;
                 }
                 store.deleteDatas.push(randomFieldId);//存放所有删除行的id
                 rowData.push(row+j);//存放所有可删除的行                    
            }
        }
        if(rowData.length==0){
            message.error(getLabel(510487,"只能删除插入的临时行"));     
            return;
        }
        let num=0;
        for (let index = 0; index < rowData.length; index++) {
            context.getActiveSheet().deleteRows(rowData[index]-num,1)    
            num++;
        }  
        message.info(getLabel(510486,"已成功删除插入的临时行"));         
        context.getActiveSheet().resumePaint();      
    }
};